﻿using System;
using System.Collections.Generic;

namespace lucere.io
{
	/// <summary>
	/// Clones of a stream access the same data, and are positioned at the same
	/// point as the stream they were cloned from.
	/// Expert: Subclasses must ensure that clones may be positioned at
	/// different points in the input from each other and from the stream they
	/// were cloned from.
	/// </summary>
	
	public interface IIndexInput : IDisposable, ICloneable
	{
	
		///<summary>Reads and returns a single byte.</summary>
		/// <see cref="IndexOutput#writeByte(byte)"></see>
		byte ReadByte();

		///<summary>
		/// Reads a specified number of bytes into an array at the specified offset.
		/// </summary>
		/// <param name="b">the array to read bytes into</param>
		/// <param name="len">the number of bytes to read</param>
		/// <param name="offset">the offset in the array to start storing bytes</param>
		/// <see cref="IndexOutput#writeBytes(byte[],int)"></see>
		void ReadBytes(byte[] b, int offset, int len);

		///<summary>
		/// Reads a specified number of bytes into an array at the
		/// specified offset with control over whether the read
		/// should be buffered (callers who have their own buffer
		/// should pass in "false" for useBuffer).  Currently only
		/// <see>BufferedIndexInput</see> respects this parameter.
		/// <see>IndexOutput#writeBytes(byte[],int)</see>
		/// <param name="b">the array to read bytes into</param>
		/// <param name="len">the number of bytes to read</param>
		/// <param name="offset">the offset in the array to start storing bytes</param>
		/// <param name="useBuffer">set to false if the caller will handle buffering.</param>
		/// </summary>
		void ReadBytes(byte[] b, int offset, int len, bool useBuffer);

		///<summary>
		/// Reads four bytes and returns an int.
		/// <see>IndexOutput#writeInt(int)</see>
		/// </summary>
		int ReadInt();

		///<summary>
		/// Reads an int stored in variable-length format.  Reads between one and
		/// five bytes.  Smaller values take fewer bytes.  Negative numbers are not
		/// supported.
		/// </summary>
		/// <see>IndexOutput#writeVInt(int)</see>
		int ReadVInt();

		///<summary>
		/// Reads eight bytes and returns a long.
		/// </summary>
		/// <see>IndexOutput#writeLong(long)</see>
		long ReadLong();

		///<summary>
		/// Reads a long stored in variable-length format.  Reads between one and
		/// nine bytes.  Smaller values take fewer bytes.  Negative numbers are not
		/// supported
		/// </summary>
		long ReadVLong();

		///<summary>
		/// Call this if readString should read characters stored
		/// in the old modified UTF8 format (length in java chars
		/// and java's modified UTF8 encoding).  This is used for
		/// indices written pre-2.4 See LUCENE-510 for details.
		/// </summary>
		void SetModifiedUtf8StringsMode();

		///<summary>Reads a string.
		/// </summary>
		/// <see>IndexOutput#writeString(String)</see>
		string ReadString();

		///<summary>
		/// Returns the current position in this file, where the next read will occur.
		/// </summary>
		/// <see>Seek(long)</see>
		long GetFilePointer();

		///<summary>
		/// Sets current position in this file, where the next read will occur.
		/// </summary>
		/// <see>GetFilePointer()</see>
		void Seek(long pos);

		///<summary>
		/// The number of bytes in the file.
		/// </summary>
		long Length { get; }

		IDictionary<string, string> ReadStringStringMap();
	}
}
